package jsyf.oa.web.device;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.device.BrandStrockFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(value = "品牌联系人接口", description = "品牌联系人接口")
@Controller
@RequestMapping("/brandStrock")
public class BrandStrockController {

    @Resource
    private BrandStrockFacade brandStrockFacade;

    @RequestMapping(value = "/selectByBrandId.json", method = RequestMethod.POST)
    public void selectByBrandId(HttpServletResponse response, @RequestBody String jsonData) {
        List<JSONObject> result = this.brandStrockFacade.selectByBrandId(jsonData);
        if (null != result && result.size() > 0) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(result));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }
    @RequestMapping(value = "/getContactsByAddress.json", method = RequestMethod.POST)
    public void getContactsByAddress(HttpServletResponse response, @RequestBody String jsonData) {
        List<JSONObject> result = this.brandStrockFacade.getContactsByAddress(jsonData);
        if (null != result && result.size() > 0) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(result));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }

    @RequestMapping(value = "/save.json", method = RequestMethod.POST)
    public void save(HttpServletResponse response, @RequestBody String jsonData) {
        Boolean result = this.brandStrockFacade.save(jsonData);
        if (result) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("records", result);
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(jsonObject));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("添加失败"));
        }
    }
    @ResponseBody
    @RequestMapping(value = "/getTelByContactByAddress.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取厂家联系人电话",
            notes = "获取厂家联系人电话 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{address:'',contact:''}", dataType = "String", paramType = "body")
    public void getTelByBrandIdAndContact(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = this.brandStrockFacade.getTelByContactByAddress(jsonData);
        if (records != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }
    @RequestMapping(value = "/getTransportCompany.json", method = RequestMethod.POST)
    public void getTransportCompany(HttpServletResponse response, @RequestBody String jsonData) {
        List<JSONObject> result = this.brandStrockFacade.getTransportCompany(jsonData);
        if (null != result && result.size() > 0) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(result));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }
}
